package com.cyandpos.pad.modifypassword.model;

import android.text.TextUtils;

import com.cyandpos.pad.common.commondata.BaseResponse;
import com.cyandpos.pad.common.netmanager.PosHttpManager;
import com.cyandpos.pad.http.OkHttpUtils;
import com.google.gson.JsonObject;

public class ModifyPasswordModelImpl implements ModifyPasswordModel {
    @Override
    public void loadModifyPasswordConfig(String newPassword,String oldPassword,String personId, final OnLoadModifyPasswordConfigListener listener) {
        //发起网络请求 成功回调
        PosHttpManager.ModifyPasswordHttpEexcute(newPassword,oldPassword,personId, new OkHttpUtils.ResultCallback() {
            @Override
            public void onSuccess(JsonObject response) {
                BaseResponse<BaseResponse> baseResponse = BaseResponse.fromJson(response.toString(), BaseResponse.class);
                if(baseResponse.getCode().equals("0")){
                    listener.onLoadModifyPasswordSuccess(baseResponse.getMsg());
                }else{
                    if (TextUtils.isEmpty(baseResponse.getTips())){
                        listener.onLoadModifyPasswordFailure(baseResponse.getTips());
                    }else {
                        listener.onLoadModifyPasswordFailure(baseResponse.getMsg());

                    }
                }
            }

            @Override
            public void onFailure(String msg) {
                listener.onLoadModifyPasswordFailure(msg);

            }
        });

    }

    public interface OnLoadModifyPasswordConfigListener{
        void onLoadModifyPasswordSuccess(String msg);
        void onLoadModifyPasswordFailure(String errorMsg);

    }

}
